/*
 * @Author: lijunqing
 * @Date: 2024-04-22 16:26:24
 * @LastEditors: lijunqing
 * @LastEditTime: 2024-04-22 16:35:13
 * @Description:
 */
const express = require("express");
const multer = require("multer");
// 创建app对象
const app = express();
const upload = multer({
  // 放到那个位置 dest 目的地
  //   dest: "./uploads",
  //   自定义名字
  storage: multer.diskStorage({
    destination(req, file, callback) {
      callback(null, "./uploads");
    },
    filename(req, file, callback) {
      callback(null, Date.now() + "_" + file.originalname);
    },
  }),
});

// 编写中间件
// single 单文件 且上传传入上传文件的名字
app.post("/avatar", upload.array("avatar"), (req, res, next) => {
  console.log(req.files);
  res.end("文件上传成功~");
});

// 启动服务器
app.listen(3000, () => {
  console.log("express服务器启动成功~");
});
